/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-20 14:56:06
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-20 20:25:25
 */
import 'package:flutter/material.dart';
import 'package:flutter_data_center/components/animation_text.dart';
import 'package:flutter_data_center/components/loading.dart';
import 'package:flutter_data_center/controller/teacher_attendance_controller.dart';
import 'package:flutter_data_center/utills/color_utils.dart';
import 'package:get/get.dart';

class DetailCard extends StatelessWidget {
  const DetailCard({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) => GetBuilder<TeacherAttendanceController>(
        builder: (_controller) => _controller.detail?.userinfo != null
            ? Container(
                width: double.infinity,
                height: 161,
                padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
                decoration: BoxDecoration(
                  color: gColor("#EBF5F5"),
                  borderRadius: BorderRadius.circular(10),
                ),
                child: Column(
                  children: [
                    Expanded(
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Container(
                            width: 50,
                            height: 50,
                            child: ClipOval(
                              child: Image.network(
                                  _controller.detail.userinfo.avatar,
                                  fit: BoxFit.cover),
                            ),
                          ),
                          SizedBox(height: 5),
                          Text(
                            _controller.detail.userinfo.name,
                            style: TextStyle(
                              fontSize: 14,
                            ),
                          ),
                        ],
                      ),
                    ),
                    Row(
                      mainAxisSize: MainAxisSize.max,
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        buildItem(_controller.detail.missing, "缺卡"),
                        buildItem(_controller.detail.late, "迟到"),
                        buildItem(_controller.detail.leave, "早退"),
                      ],
                    ),
                  ],
                ),
              )
            : Loading(),
      );

  Widget buildItem(int count, String label) {
    return Flexible(
      child: Row(
        mainAxisSize: MainAxisSize.max,
        crossAxisAlignment: CrossAxisAlignment.end,
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Text(
            label,
            style: TextStyle(
              fontSize: 14,
              color: gColor("#717171"),
              fontWeight: FontWeight.w300,
            ),
          ),
          SizedBox(width: 18),
          AnimText(
            number: count,
            style: TextStyle(
              fontSize: 16,
              fontWeight: FontWeight.w500,
            ),
          ),
        ],
      ),
    );
  }
}
